﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.Business.Purchases.ProductPrice;
using mozhi.smarterp.Business.Purchases.ProductPrices;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.Business.Controllers.Purchases
{
    [RemoteService]
    [Route("api/v1/purchases/product-prices")]
    public class PurchaseProductPriceController : BusinessController
    {
        private IPurchaseProductPriceAppService _appService;

        public PurchaseProductPriceController(IPurchaseProductPriceAppService appService)
        {
            _appService = appService;
        }

        [HttpGet]
        [Route("{id}")]
        public async Task<PurchaseProductPriceDto> GetAsync(Guid id)
        {
            return await _appService.GetAsync(id);
        }

        [HttpGet]
        public async Task<PagedResultDto<PurchaseProductPriceDto>> GetAsync(PurchaseProductPricePagedResultRequestDto filter)
        {
            return await _appService.GetListAsync(filter);
        }

        [HttpPost]
        public async Task<PurchaseProductPriceDto> CreateAsync(PurchaseProductPriceCreateDto input)
        {
            return await _appService.CreateAsync(input);
        }

        /// <summary>
        /// 获取最新采购产品单价
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("latest-prices")]
        public async Task<List<PurchaseProductPriceResultDto>> GetAsync(PurchaseProductPriceResultRequestDto filter)
        {
            return await _appService.GetListAsync(filter);
        }

        [HttpPut]
        public async Task<PurchaseProductPriceDto> UpdateAsync(PurchaseProductPriceUpdateDto input)
        {
            return await _appService.UpdateAsync(input);
        }


        [HttpDelete]
        [Route("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            await _appService.DeleteAsync(id);
        }
    }
}
